<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            list-style: none;
        }

        .box {
            width: 1000px;
            height: 800px;
            margin: 30px auto;
            display: flex;
            border: 1px solid;
        }

        #myCanvas {
            margin: auto;
            border: 1px solid;
        }
    </style>
</head>

<body>

    <div class="box">
        <canvas id="myCanvas" height="750" width="950" tabindex="333"></canvas>
    </div>
</body>
<script>
    /** @type { HTMLCanvasElement } */
    const myCanvas = document.getElementById('myCanvas');
    const ctx = myCanvas.getContext('2d');

    ctx.save();
    ctx.beginPath();

    ctx.moveTo(300, 300)
    ctx.lineTo(450, 200)
    // 由此作出向量 (150, -100)
    ctx.strokeStyle = '#f00'
    ctx.stroke()

    ctx.closePath();
    ctx.restore();

    ctx.save();
    ctx.beginPath();

    ctx.translate(300, 300)
    // 变换后，起点与坐标原点重合
    ctx.rotate(Math.PI / 180 * 100)
    ctx.moveTo(0, 0)
    // 旋转后，画出向量与上方相同的即可
    ctx.lineTo(150, -100)
    ctx.stroke()

    ctx.closePath();
    ctx.restore();

</script>

</html>